package com.itheima.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.QuestionsOption;
import com.itheima.dubbo.mapper.QuestionsOptionMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 阿鹏
 * @date 2021/3/1 20:56
 */
@Service
public class QuestionsOptionApiImpl implements QuestionsOptionApi {

    @Autowired
    private QuestionsOptionMapper optionMapper;

    @Override
    public List<QuestionsOption> findListByQid(Long qid) {
        QueryWrapper<QuestionsOption> wrapper = new QueryWrapper<>();
        wrapper.eq("qid", qid);
        return optionMapper.selectList(wrapper);
    }

    @Override
    public QuestionsOption querySumScore(String optionId) {
        QueryWrapper<QuestionsOption> wrapper = new QueryWrapper<>();
        wrapper.eq("id", Long.valueOf(optionId));
        return optionMapper.selectOne(wrapper);
    }

    @Override
    public void updateListById(List<QuestionsOption> options) {
        for (QuestionsOption option : options) {
            optionMapper.updateById(option);
        }
    }
}
